<template>
    <v-table
        :searchFlag="false"
        :hasEdit="false"
        :page="page"
        :pageSize="pageSize"
        :tableConfig="tableConfig"
        :tableData="tableData"
        :total="total"
        @findData="getTableData"
        @getTableData="getTableData"
        @searhData="setSearhData"
        @selectData="setSelectData"
        @upData="getTableData"
        ref="table"
    ></v-table>
</template>

<script>
import table from 'commons/Table'
import baseMixin from "@/mixins/BaseMixin";

export default {
    name: "Table",
    mixins: [baseMixin],
    props: {
        data: {
            type: Object
        }
    },
    data() {
        return {
            tableConfig: [
                {
                    label: this.$t('wave.orderfield'),
                    prop: "orderfield",
                    input: "select",
                    editable: true,
                    options: this.getOptions("queryOrdersColumnDrowDown/ORDRFLD")
                },
                {
                    label: this.$t('bill.operatorName'),
                    prop: "operator",
                    input: "select",
                    editable: true,
                    options: this.getOptions("querycodeLkup/OPERATOR")
                },
                {
                    label: this.$t('wave.firstvalue'),
                    prop: "firstvalue",
                    editable: true,
                    input: "input",
                },
                {
                    label: this.$t('wave.secondvalue'),
                    editable: true,
                    prop: "secondvalue",
                    input: "input",
                },
                {
                    label: "and/or",
                    prop: "andor",
                    editable: true,
                    input: "select",
                    options: this.getOptions("querycodeLkup/ANDOR")
                }
            ],
            tableData: [],
          page: 1,
            pageSize: 10,
            total: 10,
            searhData: {},
            tablelength: 0
        }
    },
    methods: {
        //获取table数据
        async getTableData(page, data) {
            try {
                let res = await this.$api.get(`/queryWpQuerybuilderdetailsListByPage/${this.$parent.$parent.$refs.detail.detailData.interactionid}/${page}`);
                
                    this.loading = false;
                    this.tableData = res.page.list;
                  this.page = res.page.curpage;
                    this.tablelength = this.tableData.length;
                    this.pageSize = res.page.pageSize;
                    this.total = res.page.total;
                    this.tableData.forEach(item => {
                        item.disabled = true;
                    })
                
            } catch (e) {
                this.$message.error(e);
            }
        },
        //搜索值
        setSearhData(data, up) {
            if (!up) {
                this.searhData = data;
            } else {
                this.searhData = data;
                this.getTableData(1, this.searhData);
            }
        },
        //选中的数据
        setSelectData(data) {
            this.$parent.setSelectData(data)
        },
    },
    mounted() {
        this.getTableData(1, {})
    },
    components: {
        'v-table': table
    }
}
</script>

<style scoped>

</style>
